package com.shen;



import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;

public class MousePosition extends JFrame implements MouseMotionListener {
        public MousePosition() {
                setSize(300, 300);
                setLocation(200, 200);
                addMouseMotionListener(this);
                setDefaultCloseOperation(EXIT_ON_CLOSE);

                addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                        }
                });

                setVisible(true);

                try {
                        Robot r = new Robot();
                        r.mouseMove(getLocation().x + 50, getLocation().y + 50);
                        r.mousePress(InputEvent.BUTTON1_MASK);
                } catch (AWTException e) {
                }
        }

        public void mouseDragged(MouseEvent e) {
                System.out.println(e.getX() + getLocation().x + ", "
                                + (e.getY() + getLocation().y));
        }

        public void mouseMoved(MouseEvent e) {
        }

        public static void main(String[] args) {
                new MousePosition();
        }
} 

